package org.sysdance.aplicativo.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;
import java.util.LinkedList;

import org.sysdance.aplicativo.entidade.DiaSemana;
import org.sysdance.aplicativo.excecao.ConexaoException;
import org.sysdance.aplicativo.integracao.DiaSemanaIntegracao;
import org.sysdance.aplicativo.util.ConexaoUtil;
import org.sysdance.aplicativo.util.ResultSetUtil;
import org.sysdance.aplicativo.util.SysDanceUtil;

public class DiaSemanaDAO implements DiaSemanaIntegracao{

	@Override
	public Collection<DiaSemana> consultarTodosDiaSemana() {
		final StringBuilder sql = new StringBuilder();
        sql.append("SELECT * FROM dia_semana ORDER BY id_dia_semana;");
        try {
            final Connection conexao = ConexaoUtil.criarNovaConexao();
            final PreparedStatement ps = conexao.prepareStatement(sql.toString());
            final ResultSet rs = ps.executeQuery();
            return ResultSetUtil.extrair(rs, DiaSemana.class);
        } catch (final ConexaoException ex) {
            SysDanceUtil.getInstancia().imprimirLog(ex);
        } catch (final SQLException sqlex) {
            SysDanceUtil.getInstancia().imprimirLog(sqlex);
        }finally{
        	try {
				ConexaoUtil.fecharConexao();
			} catch (ConexaoException e) {
				SysDanceUtil.getInstancia().imprimirLog(e);
			}
        }
        return new LinkedList<DiaSemana>();
	}

}
